# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy
from scrapy.loader import ItemLoader
from itemloaders.processors import Join, MapCompose, TakeFirst, Identity

import re
def date_covert(value):
    match_re = re.match('.*?(\d+.*)', value)
    if match_re:
        return match_re.group(1)
    else:
        return "1970-07-01"

class ArticlespiderItem(scrapy.Item):
    # define the fields for your item here like:
    pass

class ArticlespiderItemLoader(ItemLoader):
    default_output_processor=TakeFirst()

class CnblogsArticleItem(scrapy.Item):
    title = scrapy.Field()
    url = scrapy.Field()
    url_object_id = scrapy.Field()
    front_image_url = scrapy.Field(
        default_output_processor=Identity()
    )
    front_image_path = scrapy.Field()
    create_date = scrapy.Field(
        input_processor= MapCompose(date_covert)
    )
    praise_nums = scrapy.Field()
    comment_nums = scrapy.Field()
    fav_nums = scrapy.Field()
    tags = scrapy.Field(
        output_processor=Join(separator=",")
    )
    # content = scrapy.Field()